<!-- page heading start-->
<div class="page-heading">
    <h3>
        部室列表
    </h3>

</div>
<!-- page heading end-->
<div class="row">
    <div class="col-sm-12">
        <section class="panel">
            <header class="panel-heading">
                <button class="btn btn-primary" onclick="return show(this)" data-id=""
                        data-name="" data-type="0"
                        data-emp_id="" data-checker=""
                        data-deside="">
                    增加
                </button>
                <button class="btn btn-success" onclick="return download();">
                    导出
                </button>
            </header>
            <div class="panel-body">
                <table class="table table-hover general-table table-bordered">
                    <thead>
                    <tr>
                        <th width="20%">名称</th>
                        <th width="15%">制单</th>
                        <th width="15%">审核</th>
                        <th width="15%">审批</th>
                        <th width="15%">查看明细</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach($list as $val){?>
                    <tr>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $val['name'];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $emp_all_list[$val['emp_id']];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $emp_all_list[$val['checker']];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $emp_all_list[$val['deside']];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php
                                if($val['detail1'] != 0){
                                    echo $emp_all_list[$val['detail1']] . "</br>";
                                }
                                if($val['detail2'] != 0){
                                    echo $emp_all_list[$val['detail2']] . "</br>";
                                }
                                if($val['detail3'] != 0){
                                    echo $emp_all_list[$val['detail3']] . "</br>";
                                }
                                ?>
                            </span>
                        </td>
                        <td>
                            <div>
                                <button class="btn btn-primary" onclick="return show(this)" data-id="<?php echo $val['id'];?>"
                                    data-name="<?php echo $val['name'];?>" data-type="<?php echo $val['type'];?>"
                                        data-emp_id="<?php echo $val['emp_id'];?>" data-checker="<?php echo $val['checker'];?>"
                                        data-deside="<?php echo $val['deside'];?>" data-detail1="<?php echo $val['detail1'];?>"
                                        data-detail2="<?php echo $val['detail2'];?>" data-detail3="<?php echo $val['detail3'];?>"
                                >
                                    编辑
                                </button>
                                <a class="btn btn-danger" href="#"
                                   onclick="<?php echo 'return delete_data(' . $val['id'] .')';?>">删除</a>
                            </div>
                        </td>
                    </tr>
                    <?php }?>

                    </tbody>
                </table>
                <div class="pages">
                    {$page}
                </div>
            </div>
        </section>
    </div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <input type="hidden" id="id" value="<?php $val=(!empty($dept)) ?
                        $dept['id'] : ''; echo $val;?>">
                <div class="row">
                    <label class="form-inline">名称:
                    <input type="text" class="form-control" style="width: 300px;" name="name" value="<?php $val=(!empty($dept)) ?
                        $dept['name'] : ''; echo $val;?>" id="name"></label>
                </div>
                <div class="row">
                    <label class="form-inline">类型:
                        <input type="radio" class="form-control" name="type" value="0">总部
                        <input type="radio" class="form-control" name="type" value="1">分社
                    </label>
                </div>
                <div class="row">
                    <label class="form-inline">制单:
                        <select class="selectpicker" id="emp_id"  data-live-search="true">
                            <option value="">--无--</option>
                            <?php
                                foreach($emp_all_list as $k=>$emp){
                                    echo "<option value='" . $k . "'>" . $emp . "</option>";
                            }
                            ?>
                        </select></label>
                </div>
                <div class="row">
                    <label class="form-inline">审核:
                        <select class="selectpicker" id="checker" data-live-search="true">
                            <option value="">--无--</option>
                            <?php
                                foreach($emp_all_list as $k=>$emp){
                            echo "<option value='" . $k . "'>" . $emp . "</option>";
                            }
                            ?>
                        </select></label>
                </div>
                <div class="row">
                    <label class="form-inline">审批:
                        <select class="selectpicker" id="deside" data-live-search="true">
                            <option value="">--无--</option>
                            <?php
                                foreach($emp_all_list as $k=>$emp){
                            echo "<option value='" . $k . "'>" . $emp . "</option>";
                            }
                            ?>
                        </select></label>
                </div>
                <div class="row">
                    <label class="form-inline">明细:
                        <select class="selectpicker" id="detail1" data-live-search="true">
                            <option value="">--无--</option>
                            <?php
                                foreach($emp_all_list as $k=>$emp){
                            echo "<option value='" . $k . "'>" . $emp . "</option>";
                            }
                            ?>
                        </select></label>
                </div>
                <div class="row">
                    <label class="form-inline">明细:
                        <select class="selectpicker" id="detail2" data-live-search="true">
                            <option value="">--无--</option>
                            <?php
                                foreach($emp_all_list as $k=>$emp){
                            echo "<option value='" . $k . "'>" . $emp . "</option>";
                            }
                            ?>
                        </select></label>
                </div>
                <div class="row">
                    <label class="form-inline">明细:
                        <select class="selectpicker" id="detail3" data-live-search="true">
                            <option value="">--无--</option>
                            <?php
                                foreach($emp_all_list as $k=>$emp){
                            echo "<option value='" . $k . "'>" . $emp . "</option>";
                            }
                            ?>
                        </select></label>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="button" class="btn btn-primary" onclick="update();">
                        提交更改
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>
<link rel="stylesheet" href="/Public/css/bootstrap-select.min.css">
<script type="text/javascript" src="/Public/js/bootstrap-select.min.js"></script>
<script>
    function update() {
        var id = $("#id").val();
        var name = $("#name").val();
        var emp_id = $("#emp_id").val();
        var checker = $("#checker").val();
        var deside = $("#deside").val();
        var detail1 = $("#detail1").val();
        var detail2 = $("#detail2").val();
        var detail3 = $("#detail3").val();
        var type = $("input[name=type]:checked").val();
        $.ajax({
            data:{
                id:id,
                name:name,
                emp_id:emp_id,
                checker:checker,
                deside:deside,
                detail1:detail1,
                detail2:detail2,
                detail3:detail3,
                type:type
            },
            dataType:'json',
            url:'/User/Tool/roomUpdate',
            type:'get',
            success:function(res){
                window.location.reload();
            }
        })
    }
    function show(e){
        $("#id").val($(e).attr("data-id"));
        $("#name").val($(e).attr("data-name"));
        $('#emp_id').selectpicker('val', $(e).attr("data-emp_id"));
        $('#checker').selectpicker('val', $(e).attr("data-checker"));
        $('#deside').selectpicker('val', $(e).attr("data-deside"));
        $('#detail1').selectpicker('val', $(e).attr("data-detail1"));
        $('#detail2').selectpicker('val', $(e).attr("data-detail2"));
        $('#detail3').selectpicker('val', $(e).attr("data-detail3"));
        $("input[name=type]").eq($(e).attr("data-type")).attr("checked", 'true');
        $('#myModal').modal('show');
    }
    function delete_data(id){
        $.ajax({
            data:{id:id},
            dataType:'json',
            url:'/User/Tool/roomDelete',
            type:'get',
            success:function(res){
                window.location.reload();
            }
        });
        return false;
    }
    function download() {
        window.location = '/User/Tool/exportRoom';
    }
</script>